#include "Assign.h"


Assign::Assign(Expr* right,Expr* loc)
{
	this->right = right;
	this->loc = loc;
	this->op = new Token('=', "=");
	
}


Assign::~Assign()
{
}

Expr * Assign::reduce()
{
	Expr* L = this->loc->reduce();
	Expr* R = this->right->reduce();
	if (dynamic_cast<Access*>(R))
	{
		Temp* t = new Temp();
		RTL::putData(R->op, ((Access*)R)->base, ((Access*)R)->offset, t);
		RTL::putData(NULL, t, NULL, L);
	}
	else
	{
		RTL::putData(NULL, R, NULL, L);
	}
	return L;
}
